/*
 * ComponentClasses.h
 *
 *  Created on: May 29, 2013
 *      Author: root
 */

#ifndef COMPONENTCLASSES_H_
#define COMPONENTCLASSES_H_

#include "model/Component.h"
#include "XmlDefClasses.h"
#include "model/Utils.h"

class ComponentClasses : public virtual Component {
public:
	ComponentClasses();
	ComponentClasses(const ComponentClasses & otro);
	virtual ~ComponentClasses();

	ComponentClasses& operator=(const ComponentClasses & otro);

	virtual void validate(std::fstream & filestr, bool &valido) { /*TODO: implemntar*/ };

	virtual void serialize(XmlWriter & writer_rep, XmlWriter & writer_comp) {
		Utils utils;
		writer_rep.addCurrentNodeProperty(TARGET_NAME, nombre.c_str());
		writer_rep.addCurrentNodeProperty(TARGET_TYPE, utils.convertToString(componentType).c_str());
		writer_rep.addCurrentNodeProperty(TARGET_POS_X, utils.convertToString(m_posX).c_str());
		writer_rep.addCurrentNodeProperty(TARGET_POS_Y, utils.convertToString(m_posY).c_str());
	};

	virtual void deserialize(XmlReader & reader) {
		Utils utils;
		nombre = reader.getCurrentNodeProperty(TARGET_NAME);
		componentType = Component::convertIntToComponentType(utils.convertToInt(reader.getCurrentNodeProperty(TARGET_TYPE)));
		m_posX = utils.convertToUnsigned(reader.getCurrentNodeProperty(TARGET_POS_X));
		m_posY = utils.convertToUnsigned(reader.getCurrentNodeProperty(TARGET_POS_Y));
	};

	void addConnector(unsigned xRel, unsigned yRel, bool isEntry, unsigned exitNumber = 0);

protected:
	virtual void saveMyComp(XmlWriter & writer_comp) {
		xmlNode* nodoActual = writer_comp.getCurrentNode();
		writer_comp.addProperty(nodoActual, TARGET_NAME, nombre.c_str());
	};
};

#endif /* COMPONENTCLASES_H_ */
